yarn build

# 设置变量
USER="root"
SERVER="$1"
REMOTE_PATH="$3"
LOCAL_DIST_PATH="./dist"

# 使用环境变量存储密码
export SSHPASS="$2"
echo $1
echo $2
echo $3
# 禁用代理
unset http_proxy https_proxy

# 测试 SSH 连接
echo "Testing SSH connection..."
if sshpass -e ssh -o StrictHostKeyChecking=no $USER@$SERVER 'echo SSH connection successful'; then
    echo "SSH connection successful"
else
    echo "SSH connection failed"
    exit 1
fi

# 检查远程磁盘空间
echo "Checking remote disk space..."
sshpass -e ssh -o StrictHostKeyChecking=no $USER@$SERVER 'df -h'

# 使用 rsync 上传 dist 目录
echo "Starting rsync..."
if sshpass -e rsync -avz --delete -e "ssh -o StrictHostKeyChecking=no" $LOCAL_DIST_PATH/ $USER@$SERVER:$REMOTE_PATH; then
    echo "rsync completed successfully"
else
    echo "rsync failed"
    unset SSHPASS
    exit 1
fi

# 清除环境变量中的密码
unset SSHPASS

echo "Upload process completed"